<template>
	<!-- 新建来料报检单 -->
	<view>
		<u-toast ref="uToast"></u-toast><!-- 弹窗 -->
		<!-- 表单 -->
		<u-form :model="dataForm" :rules="rules" ref="dataForm" :errorType="['toast']" label-position="left"
			label-width="150" label-align="left" class="shzy-form" >

			<u-form-item label="项目名称" prop="projectName" label-width="180" class="form-item" required>
				<u-input v-model="dataForm.projectName" placeholder="请输入" border :disabled="readOnly"></u-input>
			</u-form-item>
			<u-form-item label="订单号" prop="orderNo" label-width="180" class="form-item" required>
				<u-input v-model="dataForm.orderNo" placeholder="请输入" border :disabled="readOnly"></u-input>
			</u-form-item>
			<u-form-item label="客户名称" prop="customerCode" label-width="180" class="form-item" required>
				<u-input v-model="dataForm.customerCode" placeholder="请输入" border :disabled="readOnly"></u-input>
			</u-form-item>
			<u-form-item label="工作地址" prop="gdAddress" label-width="180" class="form-item" required>
				<u-input v-model="dataForm.gdAddress" placeholder="请输入" border :disabled="readOnly"></u-input>
			</u-form-item>
			<u-form-item label="反馈日期" prop="feedbackDate" label-width="180" class="form-item" required>

				<shzy-date-time type='date' v-model="dataForm.feedbackDate" placeholder='请选择'
					class="date-class" :disabled="readOnly"></shzy-date-time>
			</u-form-item>
			<u-form-item label="反馈问题描述" prop="feedbackRemark" label-width="180" class="form-item" required>
				<u-input v-model="dataForm.feedbackRemark" placeholder="请输入" type="textarea" border :disabled="readOnly"></u-input>
			</u-form-item>
			<u-form-item label="反馈人" prop="feedbackUserId" label-width="180" class="form-item" required>
				<shzy-org-select class="date-class" v-model="dataForm.feedbackUserId" :disabled="readOnly"></shzy-org-select>
			</u-form-item>
			<u-form-item label="现场调查及处理过程" prop="process" label-width="180" class="form-item" required>
				<u-input v-model="dataForm.process" placeholder="请输入" border type="textarea" :disabled="readOnly"></u-input>
			</u-form-item>
			<u-form-item label="调查人确认" prop="confirmedUserId" label-width="180" class="form-item" required>
				<shzy-org-select class="date-class" v-model="dataForm.confirmedUserId" :disabled="readOnly"></shzy-org-select>
			</u-form-item>
			<u-form-item label="日期" prop="confirmedDate" label-width="180" class="form-item" required>

				<shzy-date-time type='date' v-model="dataForm.confirmedDate" placeholder='请选择'
					class="date-class" :disabled="readOnly"></shzy-date-time>
			</u-form-item>
			<u-form-item label="经办人" prop="handledUserId" label-width="180" class="form-item" required>
				<shzy-org-select class="date-class" v-model="dataForm.handledUserId" :disabled="readOnly"></shzy-org-select>

			</u-form-item>
			<u-form-item label="日期" prop="handledDate" label-width="180" class="form-item" required>

				<shzy-date-time type='date' v-model="dataForm.handledDate" placeholder='请选择'
					class="date-class" :disabled="readOnly"></shzy-date-time>
			</u-form-item>
			<u-form-item label="签名" prop="fIle" label-width="180" class="form-item" required>
				<image :src="dataForm.fIle" mode="" style="width: 200px; height: 100px; "></image>

			</u-form-item>
			<u-form-item label="0" prop="" label-width="180" class="form-item">

				<u-input></u-input>
			</u-form-item>
		</u-form>

		<!-- 按钮 -->
		<view class="buttom-actions">

			<u-button class="buttom-btn" type="primary" @click="signature" :disabled="readOnly">
				签名
			</u-button>
			<u-button class="buttom-btn" type="success" @click="submit" :disabled="readOnly">
				提交
			</u-button>
		</view>


	</view>
</template>

<script>
	import {
		getqmsbusicustomersurvey,
		updateqmsbusicustomersurvey,
		qmsbusicustomersurvey
	} from '@/api/q1/business/complaint/complaint.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		data
	} from '@/uview-ui/libs/mixin/mixin'
	export default {
		data() {
			return {
				dataForm: {
					fIle: '',
				},
				readOnly: false,
				rules: {
					projectName: [{
						required: true,
						message: '请填写项目名称',
						trigger: 'blur',
					}],
					orderNo: [{
						required: true,
						message: '请填写订单号',
						trigger: 'blur',
					}],
					customerCode: [{
						required: true,
						message: '请填写客户名称',
						trigger: 'blur',
					}],
					gdAddress: [{
						required: true,
						message: '请填写工作地址',
						trigger: 'blur',
					}],
					feedbackDate: [{
						required: true,
						message: '请选择反馈日期',
						type: 'date',
						trigger: 'blur',
					}],
					feedbackRemark: [{
						required: true,
						message: '请填写反馈描述',
						trigger: 'blur',
					}],
					feedbackUserId: [{
						required: true,
						message: '请选择反馈人',
						trigger: 'blur',
					}],
					process: [{
						required: true,
						message: '请填写处理过程',
						trigger: 'blur',
					}],
					confirmedUserId: [{
						required: true,
						message: '请选择调查人',
						trigger: 'blur',
					}],
					confirmedDate: [{
						required: true,
						message: '请填写日期',
						type: 'date',
						trigger: 'blur',
					}],
					handledUserId: [{
						required: true,
						message: '请选择经办人',
						trigger: 'blur',
					}],
					handledDate: [{
						required: true,
						message: '请选择日期',
						type: 'date',
						trigger: 'blur',
					}],
					fIle: [{
						required: true,
						message: '请填写签名',
						trigger: 'blur',
					}],

				},
				customerName: '',


			}
		},

		// 获取全局变量
		mounted() {

		},
		beforeDestroy() {
			// // 移除滚动事件监听
			// window.removeEventListener('scroll', this.handleScroll);
		},
		onReady() {
			this.$refs.dataForm.setRules(this.rules);
		},
		onLoad(e) {

			console.log(e)
			this.customerName = e.customer

			this.getData(e.id);

		},

		computed: {

		},
		methods: {

			getValue(result, val) {
				console.log(result, val)

				if (result == 'success') {
					this.dataForm.fIle = val


				}
			},
			getData(id) {
				getqmsbusicustomersurvey(id).then(res => {

					this.dataForm = res.data
					this.dataForm.CustomerId = id
					this.dataForm.customerCode = this.customerName
					this.dataForm.enabledMark = 1

					if (this.dataForm.fIle) {
						this.readOnly = true

					} else {
						this.readOnly = false
					}

				})

			},

			signature() {

				uni.navigateTo({
					url: '/pages/q1/business/complaintCustomer/form'
				})
			},
			submit() {

				this.$refs.dataForm.validate(valid => {
					if (valid) {
						const formMethod = !this.dataForm.id ? qmsbusicustomersurvey : updateqmsbusicustomersurvey;
						formMethod(this.dataForm).then(res => {

							if (res.code == 200 && (res.data == null || res.data == "")) {

								this.$refs.uToast.show({
									title: "提交成功",
									type: 'success',
									duration: 1000,
									callback() {
										uni.navigateBack(); // 返回上一页
									}
								});

								return;
							}
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.shzy-form {
		margin-left: 40rpx;
	}

	.form-item {
		margin-right: 40rpx;
	}

	.date-class {
		border: 1px solid lightgray;
		border-radius: 8rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
	}
</style>